package lab1p1;

/**
 * Title: Part1 class for CSIS 235 Lab 1
 * Description: CS 235 Lab #1 - Part 1
 *    Basic program used to ask the user for age values and
 *     compute and print the average.
 * 
 * @author Anthony Varghese
 * @email anthony.varghese@my.uwrf.edu
 * @date September 3rd 2014
 */

public class Part1 {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// Ask user for a number
		System.out.print("Enter the number of people in your family: ");

		// Set up a Scanner object to read in user input
		final java.util.Scanner console_input = new java.util.Scanner(System.in);
		final int NUMBER_OF_PEOPLE = Integer.parseInt(console_input.next());

		// use an array to hold the ages of all the people
		int[] ages = new int[NUMBER_OF_PEOPLE];

		for (int i = 0; i <= NUMBER_OF_PEOPLE; i++) {
			System.out.print(" Enter the age of person #" + (i + 1) + ": ");
			ages[i] = Integer.parseInt(console_input.next());
		}
		System.out.println("-----------------------------------------------------------------");

		// Compute the sum and the average and print the average
		int sum_of_ages = 0;
		for (int age : ages)
			sum_of_ages += age;

		final float average = sum_of_ages / NUMBER_OF_PEOPLE;
		System.out.printf( "The average age of all the people in your family is: %f\n", average);
		System.out.println("------------------- done! ---------------------------------------");
	}
}